package com.wfm.leetcode.editor.cn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

public class POne7电话号码的字母组合{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    List<String> res = new ArrayList<>();
    StringBuilder sb =new StringBuilder();
    HashMap<Character,char[]> map = new HashMap<>();
    public List<String> letterCombinations(String digits) {
        if(Objects.equals(digits, "")) return res;
        map.put('2',new char[]{'a','b','c'});
        map.put('3',new char[]{'d','e','f'});
        map.put('4',new char[]{'g','h','i'});
        map.put('5',new char[]{'j','k','l'});
        map.put('6',new char[]{'m','n','o'});
        map.put('7',new char[]{'p','q','r','s'});
        map.put('8',new char[]{'t','u','v'});
        map.put('9',new char[]{'w','x','y','z'});
        dfs(digits,0);
        return res;
    }
    void dfs(String digits,int start){
        if(sb.length()>digits.length()) return;
        if(sb.length()==digits.length()){
            res.add(sb.toString());
            return;
        }
        char[] chars = map.get(digits.charAt(start));
        for (int j = 0; j < chars.length; j++) {
            sb.append(chars[j]);
            dfs(digits,start+1);
            sb.deleteCharAt(sb.length()-1);
        }

    }
//    void dfs(String digits,int start){
//        if(path.size()==2){
//            res.add(new ArrayList<>(path));
//            return;
//        }
//        for (int i = start; i < digits.length(); i++) {
//            char[] chars = map.get(digits.charAt(i));
//            for (int j = 0; i < chars.length; j++) {
//                path.add(chars[j]);
//                dfs(digits,i+1);
//                path.remove(path.size()-1);
//            }
//        }
//
//    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new POne7电话号码的字母组合().new Solution();
        List<String> lists = solution.letterCombinations("23");
        System.out.println(lists);
    }
}